home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / SRC / HOARDDLL.ZIP / 3rdParty / hoard / libhoard-2.0.2 / maketable.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-25  |  2.5 KB  |  95 lines

  1. #include <iostream.h>
  2. #include <math.h>
  3.  
  4. #include "config.h"
  5. #include "heap.h"
  6.  
  7. // Use this procedure to rebuild the _sizeTable initialization
  8. // in heap.cpp if SIZE_CLASSES, ALIGNMENT, or SIZE_CLASS_BASE changes.
  9.  
  10.  
  11. #ifdef CRYSTAL_HOARD
  12. // NB: This table must match the same table in heap.cpp
  13.  
  14. #ifdef WIN32
  15. static size_t _superblockSize[hoardHeap::SUPERBLOCK_CLASSES] = { 65536UL };
  16. #else
  17. static size_t _superblockSize[hoardHeap::SUPERBLOCK_CLASSES] = { 8192UL, 65536UL, 262144UL };
  18. #endif
  19.  
  20. #endif
  21.  
  22. int main (int, char **)
  23. {
  24.   cout << "size_t hoardHeap::_sizeTable[hoardHeap::SIZE_CLASSES] = {";
  25.  
  26.   const unsigned long maxUL = (unsigned long) -1;
  27.   int j = 0;
  28.   float sz = 0.0;
  29.   while (j < hoardHeap::SIZE_CLASSES) {
  30.     // Initialize the size class lookup table.
  31.     float newSize = hoardHeap::align (ceil(pow(SIZE_CLASS_BASE, j)));
  32.     if (sz != newSize) {
  33.       sz = newSize;
  34.       if (sz > (float) maxUL) {
  35.     cout << maxUL << "UL";
  36.       } else {
  37.     cout << (unsigned long) sz << "UL";
  38.       }
  39.       if (j < hoardHeap::SIZE_CLASSES - 1) {
  40.     cout << ", ";
  41.       }
  42.     }
  43.     j++;
  44.   }
  45.  
  46.   cout << "}; " << endl;
  47.  
  48.  
  49.   cout << "size_t hoardHeap::_threshold[hoardHeap::SIZE_CLASSES] = {";
  50.  
  51.   j = 0;
  52.   sz = 0.0;
  53.   while (j < hoardHeap::SIZE_CLASSES) {
  54.     // Initialize the size class lookup table.
  55.     float newSize = hoardHeap::align (ceil(pow(SIZE_CLASS_BASE, j)));
  56.     if (sz != newSize) {
  57.       sz = newSize;
  58.  
  59. #ifndef CRYSTAL_HOARD
  60.       if (sz > (float) maxUL) {
  61.     cout << hoardHeap::MAX_EMPTY_SUPERBLOCKS * hoardHeap::SUPERBLOCK_SIZE / maxUL << "UL";
  62.       } else {
  63.     cout << hoardHeap::MAX_EMPTY_SUPERBLOCKS * MAX (1, hoardHeap::SUPERBLOCK_SIZE / (unsigned long) sz) << "UL";
  64.       }
  65. #else
  66.       // Crystal Hoard can have different superblock size classes.  Calculate the superblock size.
  67.       if ( sz > (float) maxUL)
  68.       {
  69.     cout << hoardHeap::MAX_EMPTY_SUPERBLOCKS * _superblockSize[hoardHeap::SUPERBLOCK_CLASSES - 1] / maxUL << "UL";
  70.       }
  71.       else
  72.       {
  73.         int nb = 1;
  74.         int sbClass = 0;
  75.         do
  76.         {
  77.           nb = MAX(1, ((_superblockSize[sbClass] - sizeof(superblock)) / (unsigned long)sz));
  78.         }
  79.         while ( (nb == 1) && (++sbClass < hoardHeap::SUPERBLOCK_CLASSES) );
  80.  
  81.         cout << hoardHeap::MAX_EMPTY_SUPERBLOCKS * MAX (1, _superblockSize[sbClass] / (unsigned long) sz) << "UL";
  82.       }
  83. #endif
  84.  
  85.       if (j < hoardHeap::SIZE_CLASSES - 1) {
  86.     cout << ", ";
  87.       }
  88.     }
  89.     j++;
  90.   }
  91.  
  92.   cout << "}; " << endl;
  93.  
  94. }
  95.